package com.heima.controller;


import com.heima.domain.Patient;
import com.heima.result.Result;
import com.heima.service.IPatientService;
import com.heima.vo.PatientVo;
import com.heima.vo.PatientVo2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 就诊人 前端控制器
 * </p>
 *
 * @author 黑马程序员
 * @since 2023-01-29
 */
@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private IPatientService service;
    @GetMapping("list")
    public Result list(){
        List<PatientVo> list = service.getList();
        return Result.success(list);
    }
    @GetMapping()
    public Result patientId(@RequestParam("patientId") String patientId){
        Patient byPatientId = service.getByPatientId(patientId);
        return Result.success(byPatientId);
    }
    @PostMapping("remove")
    public Result remove(@RequestParam("patientId") String patientId){
        boolean delete = service.delete(patientId);
        return Result.success(delete);
    }
@PostMapping("save")
    public Result save(@RequestParam(required = false) String patientId,
                       @RequestBody PatientVo2 vo2){
    boolean add = service.add(patientId, vo2);
    return Result.success(add);
}

}

